#include <stdio.h>
#include <dlfcn.h>

int main()
{
    void *pHandle = NULL;
    void (*pFun)() = NULL;
    int *p = NULL;

    pHandle = dlopen("./dl.so", RTLD_NOW);
    if(NULL == pHandle) {
        printf("Error, can not open dll file\n");
        exit(1);
    }

    pFun = (void(*)())dlsym(pHandle, "myprint");
    if(pFun) {
        pFun();
    }
    else {
        printf("Error, can not get function\n");
    }

    p = (int *)dlsym(pHandle, "p");
    if(p) {
        printf("p=%d,get value from dll file\n", *p);
    }
    else {
        printf("Error, can not get value from dll file\n");
    }

    dlclose(pHandle);


    return 0;
}
